Is there a cute proof of (Hausdorff space iff diagonal closed)? Let $(X,\tau)$ be a topological space, and let $\Delta_{X}=\{(x,x)\mid x \in X\}$ be its diagonal. It is known that $\Delta_X$ is closed if and only if $(X,\tau)$ is Hausdorff. I know how to prove this, but I kind of morally feel like you should be able to deduce it as the preimage of a continuous map.  
Take for example the set $$S=\{(x,y)\mid x^2+y^2<1\}$$
Then it is trivial to say that $S$ is open, since it is the preimage of the (known to be) open set $[0,1)$ in $\mathbb{R}^{+}$ under the (known to be) continuous function $f(x,y)=x^2+y^2$.  
I feel like morally I should be able to do the same here, with a function 'like' $d(x,y)=0$ if $x=y$ and $d(x,y)=1$ otherwise. However, there is the issue that I don't think I can know whether a function is continuous until I know what the open sets are in $X \times X$, which defeats the point. But there may be some functions (perhaps metrics?) which are automatically continuous. I'm not sure.
 A: So I think in some sense it's worth saying that the answer to this question is probably "no, this cannot be done." There may be some clever way to get around this, but I don't think so. In general if one has a manifold (or just a subset of $\mathbb{R}^n$) one can always describe a plethora of continuous and even smooth functions on it (if it is a smooth manifold) by taking polynomials in the coordinate functions as you do above. This obviously fails in topological spaces. We are redeemed once again in metric spaces because we have a natural choice of uniformly continuous function to $\mathbb{R}$ which allows us to naturally construct some functions on our space but that's about it.
So what remains? Given a product space $X \times X$ we have natural maps $\pi_1, \pi_2$ given by projection which are continuous open maps. Any choice of inclusion of $X$ as a slice of $X \times X$ is also continuous, in particular $X \to \Delta_{X \times X}$ is a homeomorphism. However the projection maps are pretty much it when it comes to functions on this topological space that we have for certain (it would be sort of absurd if we could write down some map, because we would be defining a map on any topological space that can be written as a product with target $\mathbb{R}$, and the only guaranteed such things are basically encapsulated by the ideas above).
So the moral of the story is that we can write $\Delta$ as the set $x \in X \times X$ such that $\pi_1(x) = \pi_2(x)$ and then we wish to show that this set is closed, but the proof, while it does involve a continuous function (in fact, two!) will more or less map bijectively with the proof that you already know, maybe modulo some extra notation.
A: Just to add to Sempliner's nice discussion:
The diagonal being closed corresponds to the following statement: if $f,g: Y \to X$ are two continuous functions, whose domain is an arbitrary topological space, and which coincide on a dense subset of $Y$, then they coincide.  (Note that $f$ and $g$ coincide if and only if the product map
$f\times g : Y \to X \times X$ factors through $\Delta_X$, so going from  closedness of $\Delta_X$ to the statement about functions is more-or-less obvious, while the other direction follows by taking $Y$ to be the closure of $\Delta_X$ in $X \times X$, and letting $f$ and $g$ be the two projections.)
So, essentially, the closedness of $\Delta_X$ is equivalent to a statement about maps into $X\times X$ (or, equivalently, pairs of maps into $X$).
To check it is equivalent to Hausdorffness from this point of view, one could use e.g. nets, thinking of $Y$ as some sort of one-point compactification of the directed set parameterizing the net.
To relate this to your question: you are instead asking for an argument that focusses on maps out of $X$.  Given the above discussion, we see that this is in some tension with the basic set-up of the situation.
For example, in the most general topological space, it may be that a closed set cannot be written as the zero set of some real-valued function; you need something like a completely regular space  for this to hold.  (This is a separation axiom that ensures that $X$ has plenty of real-valued functions defined on it.)
A: For any compact Hausdorff space $X$ or countably compact Tychonoff space $X$ or any ordered space $X$, if we can write $\Delta_X$ as the preimage of closed set of $Y$ where  $Y$ is a metric space, then $X$ is in fact metrisable itself. So your ambition is probably to high to do this for general spaces. 
Proofs: if $f: X \times X \to Y$ as described exists and $\Delta_X = f^{-1}[C]$ for some closed subset of $Y$, then $C$ is a $G_\delta$ (as $Y$ is metrisable, in fact it's enough that $Y$ is perfect) and so its inverse image $\Delta_X$ is a $G_\delta$ in $X \times X$.
Now this blog post shows that if $X$ is compact Hausdorff, and has a $G_\delta$ diagonal , it is metrisable.
Moreover this blog post does the same for countably compact spaces.
For ordered spaces the analogous fact was proved by (Bennett and?) Lutzer (IIRC, cannot find an easy reference online).
