Showing Intermediate Value property and closed preimage implies continuity Let $f : [0,1] \to \mathbb{R}$ be a function satisfying the Intermediate Value property.  Assume that for any $y \in \mathbb{R},$ the preimage $f^{-1}(\{y\})$ is closed.  Prove $f$ is continuous.
Before marking this as a duplicate, note that the hypothesis in addition to satisfying the IVP is a closed preimage.  The only problems I could find were assuming monotonicity.  I've been having trouble bringing in the closed preimage in my proof.  Also, can anyone think of any simple counter example where if we assume an open preimage of a point, the function may not be continuous? 

My thoughts:
We wish to show that there exists a $\delta > 0$ such that whenever $|x-y| < \delta, |f(x) - f(y)| < \epsilon.$
Choose an $\epsilon > 0,$ and consider the interval $(f(x) - \epsilon, f(x) + \epsilon).$  By the IVP, there exists an $a \in f^{-1}([f(x)-\epsilon,f(x)])$ and a $b \in f^{-1}([f(x),f(x)+\epsilon]).$  Maybe we could use the $a$ and $b$ to determine a $\delta,$ but I haven't brought in any closed preimage assumption.  Any help would be greatly appriciated.
 A: Fix $x_0 \in [0,1]$ and assume that $f$ is not continuous at $x_0$. Then we can find a $\varepsilon > 0$ and a sequence $x_n \rightarrow x_0$ in $[0,1]$ such that $|f(x_n) - f(x_0)| \geq \varepsilon$ for all $n \in \mathbb{N}$. By passing to a subsequence and replacing $f$ with $-f$ if necessary, we can assume that $f(x_n) > f(x_0) + \varepsilon$. By the intermediate value property, we can find $y_n$ between $x_n$ and $x_0$ such that $f(y_n) = f(x_0) + \frac{\varepsilon}{2}$. This implies that $y_n \to x_0$ and $y_n \in f^{-1}(\{f(x_0) + \frac{\varepsilon}{2} \})$. Since the inverse image is closed, we obtain $x_0 \in f^{-1}(\{f(x_0) + \frac{\varepsilon}{2} \})$ which means that $f(x_0) = f(x_0) + \frac{\varepsilon}{2}$ contradicting the fact that $\varepsilon > 0$.
For a counterexample in which the condition on the preimage fails, consider
$$ f(x) = \begin{cases} \sin \left( \frac{1}{x} \right) & 0 < x \leq 1, \\
0 & x = 0. \end{cases} $$
Then $f$ satisfies IVP, discontinuous at $x = 0$ and $f^{-1}(\{ 1 \})$ (or the preimage of any $y \in [-1,1] \setminus \{ 0 \}$ for that matter) has $x = 0$ as a limit point but $0 \notin f^{-1}(\{ 1 \})$.
