in reply to Download from Perl script corrupted for XLSX file.

After you open the file handle FH, add

binmode FH;

Perl tries to be helpful by silently converting line endings in text files to/from \r\n to \n

If your binary contains line ending sequences they will be broken.

If you look at bytes, rather than kB with the last digit truncated you will see your assertion of the files being the same size is wrong.