We may assume $y \ne 0$, because otherwise the number $\dfrac{x}{y}$ will be undefined.
If $x=0$, then $\dfrac{x}{y}=0$ and its imaginary part is also $0$.
Let's now assume that both $x$ and $y$ are non-zero.
The left hand side is
$$
|x^2|+|2xy|+|y^2|=|x|^2+2|x||y|+|y|^2
$$ while the right hand side is
$$
|(x-y)^2|=|x-y|^2=(x-y)(\bar{x}-\bar{y})=|x|^2-x\bar{y}-\bar{x}y+|y|^2,
$$
therefore if we denote by $\alpha$ and $\beta$ the arguments of $x$ and $y$, respectively, the original equation becomes
$$
2|x||y|=-x\bar{y}-\bar{x}y=-|x||y|e^{i(\alpha-\beta)}-|x||y|e^{-i(\alpha-\beta)}=-2|x||y|\cos(\alpha-\beta)
$$
The equation is then equivalent to
$$
2|x||y|[1+\cos(\alpha-\beta)]=0,
$$
i.e. $\cos(\alpha-\beta)=-1$. In particular $\sin(\alpha-\beta)=0$.
It follows that
$$
\dfrac{x}{y}=\dfrac{|x|}{|y|}e^{i(\alpha-\beta)}=-\dfrac{|x|}{|y|},
$$
and the imaginary part of $\dfrac{x}{y}$ is $0$.