TITLE: Where surjectivity goes in?
QUESTION [7 upvotes]: Let $X$ be an infinite set with the cofinite topology, and $f: X \to X$ a surjective function. Prove that $f$ is continuous if and only if $f^{-1}(\{x\})$ is finite for all $x\in X$.
I know that $f$ being onto is essential, otherwise $f$ constant is continuous, but the inverse image of the constant is the whole infinite space. 
$\implies :$ Suppose that $f$ is continuous. Given $x\in X$, $X\setminus \{x\}$ is open because $\{x\}$ is finite. By continuity, $f^{-1}(X\setminus \{x\}) = X\setminus f^{-1}(\{x\})$ is open, hence the complement $f^{-1}(\{x\})$ is finite.
$\impliedby :$ Suppose that $f^{-1}(\{x\})$ is finite for all $x\in X$. Let $\Omega$ be open. If $\Omega = \varnothing$ there is nothing to do. Otherwise $X\setminus \Omega$ is finite: $$X\setminus \Omega = \bigcup_{i=1}^n \{x_i\} \implies X\setminus f^{-1}(\Omega) = f^{-1}(X\setminus \Omega) = \bigcup_{i=1}^n f^{-1}(\{x_i\})$$ is a finite union of finite sets, hence finite. So $f^{-1}(\Omega)$ is open and $f$ is continuous. 

Question: Where did I use that $f$ is onto? If I didn't, where is the flaw in the proof?

REPLY [2 votes]: Recall that $f\colon X\to Y$ is continuous if and only if the preimage of a closed set is closed. In the cofinite topology it means that the preimage is finite, or the entire space.
But if $f^{-1}(\{x\})$ is closed, and it is the entire space, then $f$ is constant. Therefore $f$ cannot be onto, since $X$ is infinite. And indeed note that you can change the condition in the question from "surjective" to "non-constant", and the proof will work as it does.