This proof has a flaw in the second half:
Let $f:\mathbb R\rightarrow \mathbb R$ be a closed and open function.
First we prove that $f^{-1}(x)$ is finite for every $x\in \mathbb R$
suppose not, let $a_1>a_2>a_n\dots$ be a sequence of values whose image is all $x$, and such that for every $i$ there is an element in $f^{-1}(x)$ between $a_i$ and $a_{i+1}$.
Notice that $f((a_i,a_{i+1}))=f([a_i,a_{i+1}])$. Therefore $f((a_i,a_{i+1})=\mathbb R$, since it is a clopen set).
If the $a_i$'s converge then let $l$ be their limit.
We now take $b_1,b_2,\dots$ a sequence such that $a_i<b_i<a_{i+1}$ for all $i$, and such that $f(b_i)$ is a strictly increasing converging sequence ( if the $a_i$'s converge we also ask $f(a_i)>l$).
If $l$ does not exist then $\{b_1,b_2,\dots\}$ is closed while its image is not. And if $l$ exists then $\{l,b_1,b_2,\dots\}$ is closed while its image is not.
So now let $f^{-1}(0)=\{a_1,a_2,\dots, a_n\}$. Then $f$ is injective when restricted to $(-\infty,a_1),(a_i,a_{i+1})$ and $(a_n,\infty)$.
Proof: Let $U$ be a connected set which does not contain $0$ in the image, suppose $f(x)=f(y)$ for some $x\in U$. Notice that $f((x,y))$ and $f([x,y])$ differ by exactly one point. This means that $f(x,y)$ is an open set with at most $1$ limit point. Therefore $f(x,y)=\mathbb R$ or $\mathbb R \setminus f(x)$. Either case is a contradiction, since no point in $U$ maps to $0$.
We conclude that $f$ is injective when restricted to each of those open sets. Notice that the function $f$ is an open function with respect to the induced topology, since each of those sets is open. Moreover, each of these sets is isomorphic to $\mathbb R$. The following lemma finishes the proof.
Lemma: an open injection $g:\mathbb R\rightarrow \mathbb R$ is continuous.
proof: Let $h$ be the $g$ with a changed codomain, so that the function is surjective. Notice that $h^{-1}$ is a continuous bijection from a disjoint union of open sets to $\mathbb R$. (every open set is a disjoint union of open intervals).
It suffices to show that $h^{-1}$ is open on every interval, but this is clear, since a continuous injection $(a,b)\rightarrow \mathbb R$ is increasing, and hence a homeomorphism on its domain.
This shows that $f$ is continuous for every point $x$ with $f(x)\neq 0$. Using the same argument for $1$ instead of $0$ proves continuity everywhere.