in reply to Problems using pack

If you're on Unix, this will have no effect, but on Windows, maybe this is the problem... ?

After opening DATAFILE but before writing any data, try a 'binmode(DATAFILE); ' to make sure it's treated as a binary file.