The image of a proper scheme is closed

Your argument is correct, and you're almost done. The morphism $(\mathrm{id}_Y,f):Y\rightarrow Y\times_XZ$ is called the graph of $f$, sometimes denoted $\Gamma_f$. The fact you need is that, for $Z\rightarrow X$ separated, the graph of any $X$-morphism $Y\rightarrow Z$ is a closed immersion. I don't know how to do diagrams on MSE, but the point is that the graph is the base change of the diagonal $Z\rightarrow Z\times_XZ$ along $f\times\mathrm{id}_Z:Y\times_XZ\rightarrow Z\times_XZ$. Since $Z$ is separated over $X$, its diagonal is a closed immersion, so the graph is as well, being a base change of a closed immersion.

Details (and the relevant cartesian diagram) can be found in the first few pages of Chapter 9 of Goertz-Wedhorn. They can also be found in the section Separation Axioms of the Stacks Project chapter titled Schemes (currently section 21 of chapter 21, with permanent tag 01KH).

This type of argument is used a lot. I think Ravi Vakil (in his notes) calls it the cancelation principle (something like that). A precise statement is: let $P$ be a property of morphisms which is stable under composition and base change and such that closed immersions have $P$. Then for morphisms $f:Y\rightarrow Z$ and $g:Z\rightarrow X$, if $g\circ f$ has $P$ and $g$ is separated, then $f$ has $P$. The proof is just as you've outlined. You factor $f$ into its graph followed by the projection $Y\times_XZ\rightarrow Z$. The projection is a base change of $g\circ f:Y\rightarrow X$, so it has property $P$ since $g\circ f$ does, and the graph is a closed immersion because $g$ is separated, so it too has property $P$. Thus $f$ has property $P$, being a composite of morphisms with property $P$.

What you're proving is the particular case where $P$ is the property of being proper. Another would be where $P$ is the property of being finite. There is also another version of the cancelation principle where closed immersions are replaced by quasi-compact immersions and separatedness by quasi-separatedness, but the argument is exactly the same.