For $p$ an odd prime, I have seen proofs providing the classification of nonabelian groups of order $p^3$ as being isomorphic to either the Heisenberg group $Heis(\mathbb{Z}_p)$ or to the group $$\left\{ \begin{bmatrix}a & b\\ 0 & 1\end{bmatrix}:a,b\in \mathbb{Z}_{p^2},\; a\equiv 1\pmod{p} \right\}.$$
The proofs involved some clever reasoning with generators, as hinted in Hungerford's exercise of classifying order $p^3$ groups.
I attempted a different method.
Let $G$ be an order $p^3$ group and let $H$ be any subgroup of $G$ of order $p^2$, which is necessarily normal.
Take any $x\notin H$ and let $K=\langle x \rangle$.
Now, either $H\cong \mathbb{Z}_{p^2}$ or $H\cong \mathbb{Z}_{p} \times \mathbb{Z}_{p}$. Moreover, we have $K\cong \mathbb{Z}_{p}$ or $K\cong \mathbb{Z}_{p^2}$.
Let's first consider $H\cong \mathbb{Z}_{p^2}$.
If $K\cong \mathbb{Z}_{p}$, we can define two semidirect products through homomorphisms $\phi:K \rightarrow Aut(\mathbb{Z}_{p^2}) \cong \mathbb{Z}_{p(p-1)} $.
If $\phi$ were trivial, $G$ would be the abelian group $\mathbb{Z}_{p^2} \times \mathbb{Z}_{p}$.
If $\phi$ were nontrivial, then $x$ conjugates the elements of $H$ by acting as an order $p$ automorphism of $H$.
Let's now consider $K\cong \mathbb{Z}_{p^2}$ so that $H\cap K \cong \mathbb{Z}_p$ and $H$ is normal in $G$.
Though $G=HK= H \vee K$ is no longer a semidirect product of $H$ and $K$, I thought that I could still reason out as I did prior.
Indeed, if $x$ acts trivially on the elements of $K$ under conjugation, $G=HK$ would be abelian.
Otherwise, $x$ conjugates the elements of $H$ by acting as an order $p$ automorphism $\phi$ of $H$.
In this nonabelian case, $\ker\phi = H\cap K$, being the unique order $p$ subgroup of $K$.
I thought that since each element of $HK$ can be written $|H\cap K|$ times and since $H\cap K$ is also $\ker \phi$, that $G=HK$ is isomorphic to the nonabelian case when $K\cong\mathbb{Z}_p$. Loosely, I thought that the action of $x$ on the elements of $H$ matches that in the case where $K\cong \mathbb{Z}_p$, modded out by the elements of $H\cap K$. However, I got stuck. Is this a feasible approach? How would I show that the two cases are (or are not) isomorphic?