Let $f$ be a continuous function from the reals $\mathbb{R}$ onto $I=[0,1]$ with usual topology. Prove that if $C$ is a subset of $I$ and the preimage of $C$ is closed in $\mathbb{R}$ then $C$ is closed in $I$.
My attempt is to use normal space properties but it does not help.
Hint: There is a compact interval $J=[c,d]$ such that $f(J)=I$. If $(x_n)\subseteq C$ converges in $I$, take preimages and use compactness of $J$ to show that $\lim x_n\in C$.