Here $HK = \{hk :h \in H, k \in K\}$, $KH= \{kh :h \in H, k \in K\}$ and $H$ and $K$ are subgroups of a group $G$.
$\implies$: Let $HK$ be a subgroup and $e$ be its neutral element. Let $x \in KH$. Then there exist $h \in H$ and $k \in K$ such that $x = kh$. Since $k = \underbrace{e}_{\displaystyle{\in H \text{ }}} \underbrace{k}_{\displaystyle{\in K}}$, $k \in HK$. Similarly, we have that $h \in HK.$ Since $HK$ is a group, it's closed, therefore $kh \in HK$. So $KH \subseteq HK$. Now, let $y \in HK$. In a group, every element is the inverse of another element in that group, so we can write $y = (\underbrace{hk}_{\displaystyle{\in HK}})^{-1} = k^{-1}h^{-1}$, so $y \in KH$ and we're done.
$\impliedby$: Suppose $HK = KH$. Take $a = h_1k_1 \in HK$ and $b = h_2k_2 \in HK$. Then $ab = h_1\underbrace{k_1 h_2}_{\displaystyle{=hk}}k_2 = h_1hkk_2 \in HK$. Since $H$ and $K$ are subgroups, then $e \in HK$. At last, for any $x = hk \in HK$, $x^{-1} = k^{-1}h^{-1} \in HK$, since $HK = KH$.
It is all correct.
For $\Longrightarrow$, I first thought that when you arrived at $HK\subseteq KH$ you could have concluded by symmetry, but the assumption is not symmetric in that case. This makes your proof even more beautiful.