Prove that $E$ is disconnected iff there exists two open disjoint sets $A$,$B$ in $X$

Paraphrased from my answer here: If there are disjoint sets $A,B$ which intersect $E$ and such that $A\cup B\subseteq E$, then $A\cap E$ and $B\cap E$ form a disconnection of $E$, so $E$ is disconnected. Conversely, suppose that $A'$ and $B'$ are open sets such that $A'\cup B'\subseteq E$ and $A'\cap E\ne\emptyset$, $B'\cap E\ne\emptyset$, $A'\cap B'\cap E=\emptyset$ (by definition of disconnected). Then setting

$$A=\{x:d(x,A'\cap E)<d(x,B'\cap E)\}$$ $$B=\{x:d(x,A'\cap E)>d(x,B'\cap E)\}$$

we have that $A$ and $B$ are open sets (since $d(x,A'\cap E)-d(x,B'\cap E)$ is a continuous function), disjoint, and for any $x\in A'\cap E$, letting $r$ be such that $B(r,x)\subseteq A'$, we have $d(x,A'\cap E)=0$ (of course) and $d(x,B'\cap E)\ge r$ (since $A'\cap B'\cap E=\emptyset$), so $A\ne\emptyset$, and similarly $B\ne\emptyset$.