in reply to getting a filename

While the idea of storing these files in a separate directory (or even a simple DBM-based database, see tie) is the way to go, there's a Learning Opportunity here.

Constrain your split, especially if you're splitting on something that just may be part of the data you want to save. This would probably be fixed by changing the line to read:

($im, $from) = split(/im/, $message, 2);

Cultivate good habits.