Look at Andrea Ferretti's solution or Andrey Gogolev's one at MathOverflow.
In the latest, we argue by contradiction. The set $X$ is the points $x$ such that for all $a<b$, the restriction of $f$ to $(a,b)$ is not an polynomial if $x\in (a,b)$. It doesn't contain an isolated point (if $x_0$ were such a point, there would be $r>0$ such that if $|x-x_0|<r$, and $x\neq x_0$, then $x\notin X$). Let $x$ such a point, and $f$ restricted to $(a,b)$ is not a polynomial, $x\in (a,b)$. But there is an open interval $I$ containing $x_0$ and $(a,b)$, and since $x_0\in X$, $f$ restricted to this interval is a polynomial, a contradiction.
$X$ is closed, as if $x_n\to x$, $x_n\in X$ for all $n$, take $(a,b)$ containing $x$. Then it contains a $x_n$ for some $n$. So $x_n\in (a,b)$ and $f$ restricted to this interval is a polynomial.