Continuity of a map when $X$ is an infinite set endowed with the cofinite topology

Let $X$ be an infinite set endowed with the cofinite topology.

Let $f: X \rightarrow X$ be a non-constant map. Prove $f$ is continuous if and only if for every infinite set $C \subset X$, $f(C)$ is infinite.

My try:

Suppose first that $f$ is continuous and let $C \subset X$ be infinite but such that $f(C)$ is finite. Then since finite sets are closed in $X$ then $f(C)$ is a closed subset of $X$. By continuity of f it follows that $f^{-1}(f(C))$ is a closed subset of $X$, therefore finite.

But now note that $C \subset f^{-1}(f(C))$ so that $f^{-1}(f(C))$ is finite but contains the infinite set $C$, a contradiction.

Now let us show that $f$ is continuous. Since the finite union of closed sets is closed it suffices to show that for each $x \in X$ we have $f^{-1}(\{x\})$ is a closed subset of $X$, i.e $f^{-1}(\{x\})$ finite or equal $X$. Note it cannot be equal $X$ otherwise $f$ is a constant map. So we need to show that $f^{-1}(\{x\})$ is finite. Suppose not, then by assumption $f(f^{-1}(\{x\}))$ is infinite. But the latter set is contained in $\{x\}$ so $\{x\}$ contains an infinite set, an absurd.

Is this OK?

-

The first part has a slight leap of logic, where you did not rule out $f^{-1}(f(C))=X$. To do so, you can use the fact that $f$ is nonconstant, so for each $x\in f(C)$, $f^{-1}(x)$ is proper and closed, therefore finite. A finite union of finite sets is finite.