You know that $X$ is Tychonoff, so we can separate points and closed sets by continuous functions (as in the Urysohn lemma). We can now "expand" a point to a compact set, as is often the case, using covers.
So for every $x \in A$ we find a continuous function $f_x : X \rightarrow I$ such that $f_x(x) = 0$ and $f[B] = \{1\}$. This can be done as $X$ is Tychonoff.
Define for each $x \in A$: $U_x = f^{-1}[[0,\frac{1}{2})]$, which is an open set (as $f_x$ is continuous, and $[0,\frac{1}{2})$ is open in $I$) that contains $x$ (because $f_x(x) = 0 \in [0, \frac{1}{2})$). So the $U_x$, ($x \in A$) form an open cover of the compact set $A$, so finitely many of them, say $U_{x_1},\ldots,U_{x_n}$, cover $A$ as well.
Now, $g = \min(f_{x_1},\ldots,f_{x_n})$ is almost what we want: $g$ assumes only values $< \frac{1}{2}$ on $A$ (as every point in $A$ is in some $U_{x_i}$, so $f_{x_i}(x) < \frac{1}{2}$ for that $i$ and the minimum is maybe smaller still) and only the value $1$ on $B$ (as all $f_x$ are constantly $1$ on $B$). Use $g$ to get the required separating function...