open F, TMP_GIF_FNAME or die "Can not open image: $!";
You're right, that was the reason (I overlooked it, because the code became too heavy instead of several lines, written several days ago, because I coudn't create image from GIF data, only from file).