There’s a flaw in your argument for necessity: $f^{-1}[\{0\}]$ and $f^{-1}[\{1\}]$ may not be nbhds of $A$ and $B$, respectively. Consider, for example, $X=[0,1]$, $A=\{0\}$, $B=\{1\}$, and $f:X\to[0,1]:x\mapsto x$: $f^{-1}[\{0\}]=\{0\}$, which is not a nbhd of $\{0\}$, and $f^{-1}[\{1\}]=\{1\}$, which is not a nbhd of $\{1\}$.
You can fix it by using $f^{-1}\left[\left[0,\frac13\right]\right]$ and $f^{-1}\left[\left[\frac23,1\right]\right]$ instead: these really are closed nbhds of $A$ and $B$, respectively, since they contain the open nbhds $f^{-1}\left[\left[0,\frac13\right)\right]$ and $f^{-1}\left[\left(\frac23,1\right]\right]$.
Arturo has already taken care of the other half of the argument.
"Where is the connectedness of $X$ used?"
Let $A, B$ be disjoint non-empty subsets of $X$ and let $g:X\to [0,1]$ be continuous with $g[A]=\{0\}$ and $g[B]=\{1\}.$ Let $h:[0,1]\to [0,1]$ be a continuous with $h(0)=0$ and $h(1)=1,$ such that $int_{[0,1]}h^{-1}\{r\}\ne \emptyset $ for each $r\in \Bbb Q\cap [0,1].$ Let $f=h\circ g.$
Then for $r\in \Bbb Q\cap [0,1] $ we have $f^{-1}\{r\}=g^{-1}h^{-1}\{r\}\supset g^{-1} int_{[0,1]} (h^{-1}\{r\}).$
Now the set $S=int_{[0,1]}(h^{-1}\{r\})$ is a non-empty open subset of $[0,1],$ and $g$ is continuous, so $g^{-1}S$ is open in $X,$ so $$g^{-1}S \subset int_X(f^{-1}\{r\}).$$
BUT how do we know that $g^{-1}S$ is not empty?
BY THIS: $X$ is connected so its continuous image $g[X]$ is connected, with $\{0,1\}\subset g[X]\subset [0,1]$, so $g[X]=[0,1].$ And $\emptyset \ne S\subset [0,1].$ So $g^{-1}S\ne \emptyset.$
To see how this fails if $X$ is not connected, suppose $X=A\cup B$ where $A, B$ are disjoint non-empty open-and-closed subsets of $X.$ Then the $only$ continuous $f:X\to [0,1]$ with $f[A]=\{0\}$ and $f[B]=\{1\}$ is $f=(A\times \{0\})\cup (B\times \{1\}),$ and we have $f^{-1}\{r\}=\emptyset$ if $0\ne r\ne 1.$
$Addendum.$ At the proposer's request, here is how to obtain the function $h$. Let $C$ be the Cantor set. Let $[0,1]\setminus C=\cup S$ where $S$ is a family of non-empty open intervals. For $s,s'\in S$ let $s<^*s'$ iff $\sup s<\inf s'.$
Now $<^*$ is a linear order on the countably infinite set $S,$ and $<^*$ is order-dense (That is, if $s<^*s'$ then there exists $s''$ with $s<^*s''<^*s'$), and there is no $<^*$-max or $<^*$-min member of $S$.... Theorem. (Cantor): Such a linear order is order-isomorphic to $\Bbb Q$ (with the usual order on $\Bbb Q$).
And $\Bbb Q$ is order-isomorphic to $\Bbb Q\cap (0,1).$ So let $\psi: S\to \Bbb Q\cap (0,1)$ be an order-isomorphism.
Now for $x\in s\in S$ let $\phi(x)=\psi (s).$ Extend the domain of $\phi$ from $\cup S$ to $(\cup S)\cup C =[0,1]$ by letting $\phi(0)=0$ and letting $\phi(x)=\sup \{\phi (y): x>y\in \cup S\}$ when $ 0<x\in C.$ I assert without proof that $\phi:[0,1]\to [0,1]$ is continuous.
Finally for $x \in (1/4,3/4)$ let $h(x)=\phi (2x-1/2).$ For $x\in [0,1/4]$ let $h(x)=0.$ For $x\in [3/4,1]$ let $h(x)=1.$
Best Answer
You can find such $A$ and $B$ by a counting argument: let $D$ be the anti-diagonal of $\mathbb{R}_l \times \mathbb{R}_l$, so that $D = \{(x,-x): x \in \mathbb{R}_l \}$.
One can check that $D$ is closed and discrete as a subspace: e.g. $[x,x+1) \times [-x, -x+1) \cap D = \{(x, -x)\}$ so all singletons in $D$ are relatively open.
So for all subsets $A$ of $D$, $A$ and $D\setminus A$ are closed subsets of $\mathbb{R}_l \times \mathbb{R}_l $. So if the product were normal we'd have a continuous function $f_A: \mathbb{R}_l \times \mathbb{R}_l \to \mathbb{R}$ with $f_A[A] = \{0\}$ and $f_A[D\setminus A] = \{1\}$.
Note that the set $\{f_A: A \subseteq D\}$ has the same size as the powerset of $D$, i.e. $2^\mathfrak{c}$.
But $\mathbb{R}_l \times \mathbb{R}_l $ is separable, as $Q:=\mathbb{Q} \times \mathbb{Q}$ is dense, so all $f_A|Q$ should be different too (a function is uniquely determined by its values on a dense set) and there are only $\mathfrak{c}$ many real-valued functions with domain $Q$.
This contradiction shows we cannot find such $f_A$ for most subsets of $D$ in fact.