$X$ is Hausdorff if and only if the diagonal of $X\times X$ is closed
You have two things to show: that if $D$ is closed, then $X$ is Hausdorff, and that if $X$ is Hausdorff, then $D$ is closed.
Suppose first that $D$ is closed in $X\times X$. To show that $X$ is Hausdorff, you must show that if $x$ and $y$ are any two points of $X$, then there are open sets $U$ and $V$ in $X$ such that $x\in U$, $y\in V$, and $U\cap V=\varnothing$. The trick is to look at the point $p=\langle x,y\rangle\in X\times X$. Because $x\ne y$, $p\notin D$. This means that $p$ is in the open set $(X\times X)\setminus D$. Thus, there must be a basic open set $B$ in the product topology such that $p\in B\subseteq(X\times X)\setminus D$. Basic open sets in the product topology are open boxes, i.e., sets of the form $U\times V$, where $U$ and $V$ are open in $X$, so let $B=U\times V$ for such $U,V\subseteq X$. Can you see how to use this to get the desired open neighborhoods of $x$ and $y$?
Now suppose that $X$ is Hausdorff. To show that $D$ is closed in $X\times X$, you need only show that $(X\times X)\setminus D$ is open. To do this, just take any point $p\in(X\times X)\setminus D$ and show that it has an open neighborhood disjoint from $D$. I suggest that you try to reverse what I did above. First, $p=\langle x,y\rangle$ for some $x,y\in X$, and since $p\notin D$, $x\ne y$. Now use disjoint open neighborhoods of $x$ and $y$ to build a basic open box around $p$ that is disjoint from $D$.
There is a related problem:
Let $f,g:A\to B$ be two continuous maps, $B$ is a Hausdorff space and $A$ is an arbitrary space. Then the set $C(f,g)=\{x\in A| f(x)=g(x)\}$ is the coincidence set of $f$ and $g$. Prove $C(f,g)$ is closed.
to proof this, for every point $x_0$ not in $C(f,g)$, $y_f=f(x_0)$ and $y_g=g(x_0)$ are two distinguished point in $B$, because $B$ is Hausdorff, you get two disjoint open neighborhood $U(y_f)$ and $U(y_g)$, because $f,g$ is continuous, $O=f^{-1}(U(y_f))\cap g^{-1}(U(y_g))$ is open in $A$. You can verify that $O$ is a neighborhood of $x_0$ disjoint of $C(f,g)$, for if $c\in C(f,g)$ and $c\in O$, then $c\in f^{-1}(U(y_f))$ and $c\in g^{-1}(U(y_g))$, this is equal to say $f(c)=g(c)$ is in both $U(y_f)$ and $U(y_g)$, which is impossible because the two neighborhood is disjoint.
Set $A=X\times X$, $B=X$, $f=\pi_1$, $g=\pi_2$ be the projection map, you get the desired result.
Hope this can illustrate the problem you ask.
Let $(x,y)\in X\times X$, with $x\neq y$. Since $x,y\in X$, $x\neq y$, and $X$ is Hausdorff, there exist open set $\mathcal{U}$ and $\mathcal{V}$ such that $x\in\mathcal{U}$, $y\in\mathcal{V}$, and $\mathcal{U}\cap\mathcal{V}=\varnothing$. Now, $\mathcal{U}\times\mathcal{V}$ is an open subset of $X\times X$. It contains $(x,y)$. Does it intersect $D$?
Conversely, suppose $D$ is closed, and let $x,y\in X$, $x\neq y$. Then $(x,y)\notin D$, so there is an open subset $\mathscr{O}$ such that $(x,y)\in\mathscr{O}\subseteq X\times X - D$. Do you know something about open sets of a special type in $X\times X$ that might let you obtain open sets of $X$ $\mathcal{U}$ and $\mathcal{V}$ as in the previous paragraph?