If your Excel can not open a PHPSpreadsheet due to a linebreak in the first line, you should give the following code a try:
ob_end_clean();
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $newFilename. '"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
die();