Objects should be cooled before their mass is determined on a sensitive balance because it could damage the balance. Also, because it would give you wrong reading of the mass. Hot objects would warm the air around it. A warm air would expand and would produce convection as it rises causing to give the object a mass that is less than the actual. Another reason would be it would cause instability in the readings, the mass would fluctuate every now and then due to the convection currents around the object. It is always recommended to weigh the masses of objects that are in room temperature.
The elastic potential energy of a spring is given by

where k is the spring's constant and x is the displacement with respect to the relaxed position of the spring.
The work done by the spring is the negative of the potential energy difference between the final and initial condition of the spring:

In our problem, initially the spring is uncompressed, so

. Therefore, the work done by the spring when it is compressed until

is

And this value is actually negative, because the box is responsible for the spring's compression, so the work is done by the box.