The simplest answer is that sometimes IM go astray. It is best to send a notecard with your message if you suspect the friend is not online.
The more complex answer -- and probably the most likely if you have NUMEROUS messages that seem to be lost is that the person may be getting too many IMs between the time they log off and log back in again. Linden Labs caps them (I believe at 25) and any additional messages just go off into the ethers.
If they really want to get all those messages *wink* they can set an option to get IMs in email. That is under PREFERENCES in the viewer.
And as it has been said, they might just not be noticing (or just avoiding) messages that come in while they were off world. They may have subscribed to a lot of vendor groups and just don't want to deal with all those messages so close them without reading.
I would talk to your friend and see which possibility is the most likely. There are ways to better your odds on getting messages .