In Andrey Gogolev's answer the following two assertions appear:

"It is clear that $X$ is a non-empty . . . set" and "Now consider any maximal interval
$(c,e) \subset ((a,b) - X)$. Recall that $f$ is a polynomial of some degree $d$ on
$(c,e)$."

These are true, but perhaps not transparently obvious. In attempting to fill the gaps, I
developed a variation of the proof which requires neither the observation that $X$ has no
isolated points nor any argument about degrees of polynomials. Here is my adaptation,
borrowed freely from Gogolev:

I use the symbol "$\bot$" for "contradiction."

Define $I = [0,1]$ and $X = \{x \in I: \forall (a,b) \ni x: f|_{(a,b) \cap I} \; is \;
not \; a \; polynomial\}$ .

We first establish the following:

Lemma: Suppose $[c,d] \subset I$ is an interval on which $f$ coincides with a polynomial
$p$. Then there exists a maximal subinterval $[cm,dm]$ having the properties $[c,d]
\subset [cm,dm] \subset I$ and $f = p$ on $[cm,dm]$. Furthermore, $cm \in X \cup \{0\}$
and $dm \in X \cup \{1\}$.

Proof: Let $cm$ = LUB $\{x: f(x) \neq p(x)\} \cup \{0\}$ and $dm$ = GLB $\{x: f(x)
\neq p(x)\} \cup \{1\}$. It is clear that $[cm,dm]$ is maximal. Supppose that $cm
\not \in X$ and $cm \neq 0$. Then we can find another interval $(u,v)$ with $cm \in (u,v)
\subset I$ on which $f$ coincides with a polynomial $q$. But on $[cm,v]$ we have $f = p =
q$, whence $f = p$ on $[u,dm]$. Since $u < cm$, we see that $[cm,dm]$ is not maximal
($\bot$). Therefore, $cm \in X$ or $cm = 0$. Likewise, $dm \in X$ or $dm = 1$.

Now we begin the proof-by-$\bot$ of the main result. Suppose that $f$ is not a polynomial
on $I$.

If $X = \emptyset$, we begin with any $[c,d]$, and the lemma tells us that $cm = 0$ and
$dm = 1$, so $f$ is a polynomial on $I$ ($\bot$). Thus, $X \neq \emptyset$. Now define
$S_n = \{x: f^{(n)}(x) = 0\}$. $X$ and $S_n$ are clearly closed. Applying the Baire
category theorem to the covering $\{X \cap S_n\}$ of the complete metric space $X$, we get
that there exists an interval $(a,b)$ such that $(a,b) \cap X \neq \emptyset$ and $(a,b)
\cap X \subset S_n$ for some $n$. (It is important here that $S_n$ is closed.)

Put $J = (a,b) \cap I$, and let $a1$ and $b1$ be the left and right end-points of $J$.
(Observe that it is possible that $a1 = 0$ or $b1 = 1$, so J may not be open.) If $J
\subset S_n$, then $f$ is a polynomial on $J$, whence $(a,b) \cap X = (a,b) \cap I \cap X
= J \cap X = \emptyset$ ($\bot$). Thus, we can choose a point $t \in J - S_n$. Now $t
\not \in X$, since $(a,b) \cap X \subset S_n$. Therefore, we can find an interval $(c,d)
\ni t$ such that $f$ coincides with a polynomial $p$ on $(c,d) \cap I$. Furthermore, $f =
p$ on the closure of $(c,d) \cap I$, which is an interval of the form $[c1,d1] \subset I$.
Apply the lemma to $[c1,d1]$ to obtain a maximal interval $[cm,dm]$ having the stated
properties. Since $t \not \in S_n$ and considering $p$, we see that $cm \not \in S_n$.
Suppose $cm > a1$. Then we have $a \le a1 < cm \le c1 \le t < b$, so $cm \in (a,b)$.
From the lemma, $cm \in X$, since $cm > a1 \ge 0$. Thus, $cm \in (a,b) \cap X \subset
S_n$ ($\bot$). Therefore, $cm \le a1$. Likewise, $dm \ge b1$. Thus, $f$ is a polynomial
on $J \subset [a1,b1] \subset [cm,dm]$, whence, as above, $(a,b) \cap X = \emptyset$
($\bot$). We are at last forced to conclude that $f$ must indeed be a polynomial on $I$.