Let us see that $X$ is Hausdorff, in effect:
Let $x_1,x_2 \in X$, as $g\circ f=1_x$ then $f$ is injective and therefore.
$$f(x_1)\neq f(x_2)\longrightarrow y_1\neq y_2$$
Since $Y$ is a hausdorff space then there exist $V_1,V_2 \subset Y$ open and disjoint such that
$$y_1\in V_1 \ y \ y_2\in V_2$$
Since f is continuous $$f^{-1}(V_1)=U_1$$ $$f^{-1}(V_2)=U_2$$
With $U_1$, $U_2$ are open and furthermore,
\begin{equation*}
\begin{split}
U_1\cap U_2=&f^{-1}(V_1)\cap f^{-1}(V_2)\\
=&f^{-1}(V_1\cap V_2)\\
=&f^{-1}(\emptyset)\\
=&\emptyset
\end{split}
\end{equation*}
where $U_1, U_2 \in X$, with $x_1in U_1, x_2 \in U_2$, so $X$ is hausdorff.
\vspace{5mm}
\Now we prove that $f(X)$ is closed in Y, indeed, let us consider the function:
\begin{equation*}
\begin{split}
h: Y \longrightarrow \ X \times Y & \longrightarrow Y\times Y \\
y \longrightarrow (g(y),y) &\longrightarrow (f(g(y)),y)
\end{split}
\end{equation*}
$h$ is continuous because it is the composition of continuous functions, as $Y$ is hausdorff the diagonal $\Delta_y \subset Y \times Y$ is closed and therefore,
$$f(X)=h^{-1}(\Delta_y)$$ is closed.