I have the question above and now I am trying to prove that x is homotopic to z.
My Idea is as follows:
Let $H(x,t)$ be the homotopy between x•y and z•u because y and u are homotopic I can substitute them for their homotopy class [w].
This means I can write the concatenations as x•[w] and z•[w].
Can I now say that because [w] stays the same when I apply $H(x,t)$ I have a homotopy between x and z or do I still need something else?
You cannot say that $[w]$ stays the same when you apply $H(x,t)$. In fact, it's not clear what that means. A homotopy is not an operation on functions, it is a relation between functions. I suspect what you're thinking is that $H_t \simeq \gamma\cdot w$ for some $w\in [y]=[u]$ for all $t$, but this is not necessarily true. Also $[w]$ is a homotopy class, i.e., a set of maps. While I can interpret the composite $x\cdot [w]$, I'm not sure my interpretation matches with what's in your head. I interpret it as the homotopy class $[x\cdot w]$ for any $w\in [w]$.
Anyway, instead, try the following. (I'm assuming you haven't seen the fundamental group yet, but are familiar with the homotopies for associativity and identity of path concatenation.)
If $\gamma$ is a path, let $\gamma^{-1}(t) = \gamma(1-t)$ be the reversed path.
Now prove that you have the following four (six technically, see the warning below) homotopies. $$x\simeq x\cdot y\cdot y^{-1} \simeq z\cdot u \cdot y^{-1} \simeq z\cdot u \cdot u^{-1} \simeq z.$$
Note that the middle two are basically the given homotopies (though be careful with the path composites), so really you just need to find a homotopy $\gamma\cdot \gamma^{-1}\simeq p$, where $p$ denotes the constant path.
Warning, although I've written it as if there's only four homotopies, path composition is not associative, it's only associative up to homotopy. Thus when I write $x\cdot y \cdot y^{-1}$ without parentheses, I am hiding a homotopy. (I'm sort of hoping you've at least seen this before, so I didn't want to focus too much on the minor details.)
Hint:
Edited
If you've seen the fundamental group, then observe that the given information is that $[x\cdot y] = [z\cdot u]$ and that $[y]=[u]$. Then $$[x][y]=[x\cdot y]=[z\cdot u] = [z][u] = [z][y],$$ and cancelling $[y]$ from both sides (since the fundamental group is a group), we have $[x]=[z]$, as desired.