Let $X$ be any countably infinite space whose topology is $T_1$ but not discrete, and let $f:X\to\Bbb N$ be a bijection. Give $\Bbb N$ the discrete topology. Then $X$ is the union of the countably many closed sets $\{x\}$ such that $x\in X$, and of course $f\upharpoonright\{x\}$ is continuous for each $x\in X$, but $f$ is not continuous on $X$. If $X=\Bbb Q$ with the usual topology, $f$ is not continuous at any point of $X$.
If you want the space $X$ to be compact, you can take it to be $[0,1]$ and use the function
$$f:[0,1]\to[0,1]:x\mapsto\begin{cases} 0,&\text{if }x=0\\ 1,&\text{if }0<x\le 1\;. \end{cases}$$
Take your closed sets to be $F_0=\{1\}$ and the intervals $F_n=\left[\frac1n,1\right]$ for $n\in\Bbb Z^+$; $f$ is constant and therefore certainly continuous on each of the closed sets $F_n$.