Existence of such a function goes back to 1939:
J. Gillies, Note on a conjecture of Erdos, Quart. J. Math. Oxford 10, 1939, 151-154
Also, it can be shown that there is a residual set (a set whose complement is of first category) of continuous functions on $[0,1]$ such that $f^{-1}(\lbrace \alpha \rbrace)$ is perfect except for countably many $\alpha$ and for each of the exceptional $\alpha 's$, $f^{-1}(\lbrace \alpha \rbrace)$ has the form $P\cup\lbrace t\rbrace$ where $P$ is perfect and $t$ is an isolated point of $f^{-1}(\lbrace \alpha \rbrace)$.