\(=x^2y-x^2z+y^2z-xy^2+z^2\left(x-y\right)\\ =\left(x^2y-xy^2\right)-\left(x^2z-y^2z\right)\\ =xy\left(x-y\right)-z\left(x-y\right)\left(x+y\right)+z^2\left(x-y\right)\\ =\left(x-y\right)\left(xy-xz-yz+z^2\right)\\ =\left(x-y\right)\left(y-z\right)\left(x-z\right)\)