So, why don't you just save your data as a 24-bit BMP image? Those are pretty simple format. It contains a pretty simple header, which is just a few bytes, followed by : Blue value (1 byte); Green value (1 byte); Red value (1 byte); at the end of a horizontal line, there are two zero bytes. Next line. Same thing. At the end of the file: two zero bytes. Pretty simple. You should write your own SaveBMP() function. I am thinking about writing one, because I may need it as well....
sub SaveBMP # Usage: SaveBMP($filename, $width, $height, $image_data)
{
...
}