I think this line
file_put_contents($current_mail_file_path, $buffer, FILE_APPEND);
should be
file_put_contents($current_mail_file_path, $current_mail , FILE_APPEND);
Workaround: Use a text editor to manually remove the first line of every generated file except the first one