
The work done to move q1 from infinity to A is, W1 = 0 (∵ There is no initial electric field)
The work done to move q2 from infinity to B is, W2 = V1Bq2
Where V1B is the electric potential at B due to q1, it is given by
\(V_{1B} = \frac{1}{4 \pi \epsilon_0 \left(\frac{q_1}{r_{12}}\right)}\)
\(\Rightarrow W_2 = V_{1B} q_2 = \frac{1}{4 \pi \epsilon_0} \left(\frac{q_1}{q_2}\right) q_2\)
The potential energy of this system of charge is equal to total work done to build this configuration. Therefore
\(U= W_1 + W_2 = 0 + \frac{1}{4 \pi \epsilon_0} \left(\frac{q_1 q_2}{r_{12}}\right)\)
\(\Rightarrow U = \frac{1}{4 \pi \epsilon_0} \left(\frac{q_1q_2}{r_{12}}\right)\)