Is it possible to have the set $f^{-1}(\lbrace x \rbrace)$ perfect for every $x$?

Per Malik's comment, the $y$ coordinate of the Peano curve is such a function. This it is because it is constructed using subdivision of the interval into dyadic squares, so the inverse image of each square is an interval, and the inverse image of a sufficiently small square is a sufficiently small interval. But clearly a square around a point contains other points with the same. $y$ coordinate.


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 for any $f$ in that set $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)$.