More precisely, what your textbook ought to say is that the pointwise supremum of a countable set of measurable functions is measurable.
As was pointed out by Dyland Moreland and azarel in the comments, this result is in a context where measurable functions are allowed to have codomain $[-\infty,+\infty]$ rather than $\mathbb R$. You gave an example of a countable set of measurable functions whose pointwise supremum is the constant function $f(x)=+\infty$, and $\{x:f(x)>a\}=[0,1]$ for all $a\in\mathbb R$, showing that $f$ is measurable.
The reason you cannot generally allow suprema of arbitrary sets of measurable functions while staying measurable is because you cannot generally allow arbitrary unions of measurable sets while staying measurable. If $E$ is a nonmeasurable set, then $E$ is a union of measurable sets, $E=\bigcup\limits_{x\in E}\{x\}$. Similarly, $\chi_E$ is a nonmeasurable function, but it is a supremum of measurable functions, $\chi_E(x)=\sup\limits_{y\in E}\chi_{\{y\}}(x)$.
To see more explicitly where countable unions come in, note that for all $a\in\mathbb R$, $\{x:\sup_n f_n(x)>a\}=\{x:\exists n, f_n(x)>a\}=\cup_n\{x:f_n(x)>a\}$.