Why is methyl iodide more dense than ethyl iodide, even though the latter has more carbon atoms? It is understood that more carbon atoms present in a hydrocarbon, the greater the density of the hydrocarbon.

But then why does $\mathrm{CH_{3}I}$ have a greater density than $\mathrm{C_{2}H_{5}I}$?
For the same reason why a bucket of sand will weigh more than a bucket of rocks.
Smaller molecules will result in a more dense, thus more heavy substance.