It looks like you are just missing the negative sign in front of the potential energy expression. Let me explain.
Let us imagine the dipole to be at some angle in space with an electric field pointing horizontally to the right for simplicity.
In this scenario, the torque $\vec\tau$ = $\vec r_1$ $\times$ $q\vec E$ + $\vec r_2$ $\times$ $-q\vec E$ where $\vec r_1$ is the moment arm of the dipole towards the positive charge, $\vec r_2$ is the moment arm of the dipole towards the negative charge (both are of same magnitude in this case) and $\vec E$ is the electric field.
Evaluating the cross product, $\vec\tau$ = $-2rqE\sin\theta$ $\hat k$ as the electric field causes both $q$ and $-q$ to rotate in the clockwise direction.
Now, since the force caused by the electric field is conservative, we can say that:
$$\Delta U = -\Delta K = -W_E = -\int\vec\tau\cdot d\vec\theta = 2rqE\int\sin\theta d\theta = -2rqE\cos\theta$$
If we define the dipole moment $|\vec p| = 2rq$, then $\Delta U = -pE\cos\theta$ or $-\vec p\cdot\vec E$.