I honestly thought a lighter aircraft would glide further compared to heavy aircraft
This is just one of those strange things where normal logic might suggest something different to what happens. There are plenty of technical references (beware of some brain strain, though) which go into the mathematics (eg
archive.aoe.vt.edu/lutze/AOE3104/glidingflight.pdf) and the end result is that it all depends on lift/drag. Speed, per se, doesn't drive the outcome directly. While the weight will affect ROD, we are interested in the glide angle so aircraft gliding speed is the other factor involved.
The maximum value of lift/drag is what we are after and that will be driven by the relevant angle of attack during the glide. It just happens that, to achieve this angle of attack at a higher gross weight, we need to go a bit faster.
If it spends less time in the air then how would it glide further compared to lighter aircraft?
If we have the heavier aircraft gliding at a higher speed to achieve the same glide angle as the lighter aircraft, it will get to the end height (say, ground level for a straight in forced landing) quicker as the higher speed gets it there in a shorter time interval. The effect of any wind will be less during that shorter time (just the normal navigation problem, here) so, comparing the lighter and heavier aircraft, starting from the same still air glide distance, the faster (heavier) aircraft will suffer a lesser wind effect and go just that little bit further than the slower (lighter) aircraft which suffers the head wind for a longer period of time.