Let us say a given topological space $X$ has property $P$ if for every closed subset $A \subset X$ there is a continuous function $f : X\rightarrow \Bbb R$ such that $A = f^{-1}(\{0\})$.
As I understand, every metrizable space has property $P$. Specifically, if $X$ is metrizable with metric $d$ and $A \subset X$ is a closed subset then the function $f(x) = \mathrm{inf}_{a \in A} d(a,x)$ is a continuous real-valued function on $X$ which is 0 on $A$ and nonzero on the complement of $A$. (The last part follows from $A$ being closed.)
My question is whether there is a non-metrizable topological space $X$ with property $P$?
The condition that every closed subset of $X$ is a zero set is called "perfectly normal". Equivalently, that for every every two disjoint closed subsets $A$ and $B$ there is a continuous $f : X \to [0,1]$ such that $f^{-1}[\{0\}] = A$ and $f^{-1}[\{1\}] = B$. Equivalently, that $X$ is normal and every closed set is a $G_\delta$ set. This equivalence is called Vedenissoff Theorem.
Every metric space is perfectly normal and Hausdorff, also known as a $T_6$ space.
The π-Base contains many examples and counterexamples in topology.
Maybe one of the easiest to see which is perfectly normal but not metrizable is if you let $X = \{0,1\}$ with the trivial topology. Then $X$ is perfectly normal since the only closed subsets are $\emptyset$ and $X$, for which the constant $1$ and constant $0$ functions satisfy the requirements. On the other hand, $X$ is not metrizable since it is not Hausdorff.
If you want a counterexample that is also Hausdorff you have to work a little harder. One such example is the Sorgenfrey line or the right half-open interval topology on $\mathbb{R}$. Namely, you let $X = \mathbb{R}$ and consider the topology generated by the basis of all half-open intervals $[a,b)$. The idea is that $X$ is separable, but not second-countable, so by Urysohn's metrization theorem $X$ is not metrizable. On the other hand, you can show $X$ is normal and every open set is $F_\sigma$.