For continuous $f$ and $g$, $\{x \in X: f(x)=g(x)\}$ is closed $\mathbf{Question}:$Let $(X,d_1)$ and $(Y,d_2)$ be two metric spaces and $f,g: X \mapsto Y$ be two continuous functions. Then prove that $\{x \in X: f(x) =g(x)\}$ is closed in $X$. 
Approach: We consider the function $h: X \mapsto \mathbb{R^+}\cup \{0\}$ defined by $h(x)=d_2(f(x),g(x))$
Lemma 1: $h(x)$ is continuous on $X$. 
Proof: We have $d_2(f(x),g(x))+d_2(g(x),g(c))+d_2(f(x),f(c))\geq d_2(f(c),g(c))\implies d_2(g(x),g(c))+d_2(f(x),f(c))\geq d_2(f(c),g(c))-d_2(f(x),g(x))$.
Symmetry gives us $d_2(g(x),g(c))+d_2(f(x),f(c))\geq d_2(f(x),g(x))-d_2(f(c),g(c))$
Now, for any $\epsilon>0$, $\exists$ $\delta>0$ such that $d_2(g(x),g(c))< \epsilon/2$ and $d_2(f(x),f(c))<\epsilon/2$ whenever $d_1(x,c)<\delta$.
Hence, we conclude $\forall \epsilon>0, \ \exists \delta>0$ such that $|h(x)-h(c)|<\epsilon$ whenever $d_1(x,c)<\delta$, which establishes the lemma. 
Now, $h(x)=0$, iff $f(x)=g(x)$. 
We know that $\{0\}$ is a closed set in $\mathbb{R^+}\cup \{0\}$ and that the inverse image set of a closed set under a continuous mapping is a closed set. 
Hence $\{x \in X: h(x)=0\} \equiv \{x \in X: f(x)=g(x)\}$ is a closed set in $X$.
$\mathbf{Follow-up \ question}:$ If $A \subseteq X$ is dense in $X$ and $f(x)=g(x), \forall x \in A$, then $f=g$ on $X$. 
Attempt: By the previous theorem, $D=\{x \in X: f(x)=g(x)\}$ is closed in $X$. Now, suppose, for some $k \in X \setminus A$, $f(k) \neq g(k)$. But, $A\subset D \implies A' \subset D'$ (derived set) $\implies k \in D'$ but $k \notin D$ which contradicts the fact that $D$ is closed. 
Is this correct? Please verify. 
 A: More generally, the function $h:X\to Y\times Y$ defined by $$h(x)= (f(x),g(x))$$ is continuous, since $f$ and $g$ are continuous, and the set $$\Delta = \{(y,y): y\in Y\}$$ is closed if $Y$ is Hausdorff.
Therefore the inverse image of a closed set
$$ h^{-1} [\Delta] = \{x \in X: f(x) =g(x)\}$$ is closed.

For a real valued function $f:X\to R$ note that
$$\{x \in X: f(x) =g(x)\}=\{x \in X: f(x) -g(x)=0\}=$$
$$ (f-g)^{-1} (\{0\})$$
Since $f-g$ is continuous and $\{0\}$ is closed,  the inverse image of a closed set is closed, therefore $$\{x \in X: f(x) =g(x)\}$$ is closed.
A: Note : $\to$ means "converges to" in whatever metric space the elements to the right and left of $\to$ belong to.
Your proof is correct.
However, you may also observe that since we are in the metric space setting, all proofs involving continuity/density may be extended to the sequential definitions.
For example, to show that $D$ is closed, it is enough to show that if $x_n \in D$ and $x_n \to x$, then $x \in D$. However, if $x_n \to x$, then by continuity, $f(x_n) \to f(x)$ and $g(x_n) \to g(x)$. Since $f(x_n) = g(x_n)$ for all $n$ it follows that $f(x) = g(x)$ by uniqueness of limits, giving $x \in D$ and hence closure of $D$.
The second proof is also right, a better way of saying things : If $f = g$ on $A$ , whose closure is $X$, then $A$ is contained in $D$ which is closed, so $D$ must contain $X$ by definition of closure being the smallest closed set containing a given set. Now, $f=g$ on $D$ so $f = g$ on $X$. You may also go sequentially : if $x \in X$, then by density there is $x_n\in A$ so that $x_n \to x$, ... (do it yourself and get $f(x) = g(x)$, which implies frmo arbitrariness of $x$ that $f=g$ on $X$).
A: Both proofs look fine.
That said, the proof to the follow up question is perhaps awkward in its use of contradiction.  A direct proof with the same flavor is given by
$$A \subseteq D \implies X = \bar{A} \subseteq \bar{D} = D \subseteq X \implies D=X$$
A: Your proof is correct. However to avoid using $\epsilon$ - $\delta$ I would say
$$A = \{x \in X: f(x) =g(x)\} = \bigcap_{n \in \mathbb N} A_n$$ where $A_n = \{x \in X: d_2(f(x) ,g(x)) \le 1/n\}$. $A_n$ is closed as the inverse image of the closed subset $[0, 1/n]$ under the continuous map $\varphi : x \mapsto d_2(f(x),g(x))$. $\varphi$ being continuous as a composition of continuous maps.
$A$ is closed being an intersection of closed subsets.
And I agree with your second proof two.
