Electric potential energy of a dipole is given as
[tex]U = - P.E[/tex]
[tex]U = - PE cos\theta[/tex]
so change in the potential energy is given by
[tex]U_f - U_i = (-PEcos\theta_2)- (-PEcos\theta_1)[/tex]
[tex]\Delta U = PE (cos\theta_1 - cos\theta_2)[/tex]
here initially it was parallel to electric field while finally it is perpendicular to the electric field
so we have
[tex]\Delta U = PE(cos 0 - cos 90)[/tex]
[tex]\Delta U = PE[/tex]
so above is the change in potential energy of dipole