Union of connected subspaces $A$ and $B$ of $X$ such that $A\cap \overline{B} \ne \varnothing$ is connected

I want to prove the following proposition:

Let $X$ be a topological space, $A \subseteq X$ and $B \subseteq X$ connected subspaces such that $A\cap \overline{B} \ne \varnothing$. Then, $A\cup B$ is connected.

I am aware that this was already discussed in Union of connected subsets$X$,$Y$ is connected if $\overline{X}\cap Y \neq \varnothing$, but I want to check my proof, which uses the inexistence of separation of a connected space, unlike the answer to the linked question.

My proof:
Suppose $A\cup B$ is not connected. Thus, there exists a separation $(U,V)$ of $A\cup B$ (i.e there are non-empty disjoint open sets $U,V$ of $A\cup B$ such that $U\cup V=A\cup B$).
Since $A\subseteq A\cup B$ is an open set of the topological space $A$ and $V$ is open in $A\cup B$, then $A\cap V$ is an open set of the space $A$ (with the subspace topology). By the same token, $A\cap U$ is also an open set of $A$.
Clearly, $(A\cap U)\cup (A\cap V)=A$. Hence, if $A\cap U$ and $A\cap V$ are both nonempty, then we've arrived at a pair of disjoint nonempty open sets of $A$ whose union is $A$ $\rightarrow$ contradiction because $A$ is connected.
Hence, either $A\cap U=\varnothing$ or $A\cap V=\varnothing$ (but not both, since the points of $A$ must be in one of them). Let's suppose, without loss of generality, that $A\cap V=\varnothing$ (and so $A\cap U\ne\varnothing$).
Now, just like for $A$, we have $B\cap U=\varnothing$ or $B\cap V=\varnothing$ (but not both). If $B\cap V=\varnothing$, then $(A\cup B)\cap V=(A\cap V)\cup (A\cap V)=\varnothing$, and hence $V=\varnothing$ (since $V\subseteq A\cup B$)$\rightarrow$ absurd. Thus $B\cap U=\varnothing$ and $B\cap V\ne\varnothing$.
From this, $A=U$ (if $x\in A$, then $x\in U$ or $x\in V$, and thus $x\in U$; reciprocally, if $x\in U$ then $x\in A$ or $x\in B$, and so $x\in A$). Similarly, $B=V$.
Therefore, $a$ and $B$ are a separation of $A\cup B$ (in fact, by what we've just seen this is the only possible separation of $A\cup B$). Now, let $x\in A\cap \overline{B}$. Since $x\in A$,$\ x\notin B$. but $B$ is closed and so $B=\overline{B}$. Hence, $x\in A$,$\ x\notin \overline{B}$ $\rightarrow$ absurd.
Therefore, $A\cup B$ is connected. $\ \square$

My question:
I've written (in bold) that "$B$ is closed and so $B=\overline{B}$". But I don't know how to justify that $B$ is closed (in $X$). It is closed in $A\cup B$, since $A$ is open and $(A\cup B)-B=A$, but how can I conclude that it is closed in $X$?

$B$ does not have to be closed in $X$, but it is closed in $A ∪ B$, and that is what you need.
• I understand that $\overline{B}$ is connected, but why does that mean that I can suppose $B$ to be closed w.l.o.g? – Soap Feb 2 '17 at 19:04
• We are considering whether $A ∪ B$ is connected, so we want $\overline{B}$ in $A ∪ B$. – user87690 Feb 2 '17 at 19:59
• You have that $B$ is closed in $A ∪ B$, but at the same time you have that $x ∈ A ∩ \overline{B}$. That is a contradiction. Also note that the connectedness of $A ∪ B$ has nothing to do with $X \setminus (A ∪ B)$, it is a property of the space $A ∪ B$ itself, so you could have supposed $X = A ∪ B$ w.l.o.g. – user87690 Feb 2 '17 at 21:39
• $A$ is open in $A ∪ B$ and $B$ is disjoint from $A$, so how could possibly $\overline{B}$ meet $A$? – user87690 Feb 2 '17 at 22:00
It is not in general true that $B=\overline{B}$. However, we are led to a contradiction anyway:
Suppose $A\cap \overline{B}\ne \varnothing$. Let $x$ belong to $A\cap \overline{B}$. Since $x\in \overline{B}$, any neighborhood of $x$ has non-empty intersection with $B$. In particular, since $A$ is an open neighborhood of $x$ (remember that $A$ is open), we get $A\cap B\ne \varnothing$. This is a contradiction because $A$ and $B$ were disjoint.
This completes the proof. $\ \square$