Initially, length and breadth were touching the ground.
Height of center of mass(CM), = h/2
potential energy(initial PE) = mg(h/2) = mgh/2
finally, breadth and height were touching the ground
Height of center of mass(CM), = l/2
potential energy(final PE) = mg(h/2) = mgl/2
work done = change in energy = final PE - initial PE = mgl/2 - mgh/2 = mg(l-h)/2
work done is mg(l-h)/2.