Running PHPSpreadsheet via crontab on DigitalOcean – not saving

When I run the following script via a browser using the URL, all emails are sent, the XLSX is saved where it should be and the result is very quick.

However, when it runs via crontab, it sends me the first two emails but not the last one and it doesn’t save the XLSX file, making me believe there’s an error at this point.

Unfortunately I don’t get any error messages in the log file.

<?php

require dirname(dirname(__FILE__)).'/vendor/autoload.php';
use PhpOfficePhpSpreadsheetSpreadsheet;
include dirname(dirname(__FILE__)) . '/includes/mail.php';

//SEND AN EMAIL TO ME: "STARTED CRON"

$spreadsheet = new Spreadsheet();
$newsheet = new PhpOfficePhpSpreadsheetWorksheetWorksheet($spreadsheet, "My first sheet");
$spreadsheet->addSheet($newsheet);

$activesheet = $spreadsheet->setActiveSheetIndexByName("My first sheet");
$activesheet->getTabColor()->setRGB("FF0000");
$activesheet->setCellValue("A1", "Test");
$activesheet->setCellValue("A2", "Some numbers...");
$activesheet->setCellValue("A3", 1);
$activesheet->setCellValue("A4", 2);
$activesheet->setCellValue("A5", "=SUM(A3:A4)");

$activesheet->getStyle("A1")->getFill()->setFillType(PhpOfficePhpSpreadsheetStyleFill::FILL_SOLID);
$activesheet->getStyle("A1")->getFill()->getStartColor()->setARGB("FFC6EFCE"); //LIGHT GREEN

//SEND AN EMAIL TO ME: "SET THE DATA"

$destinationfile = "/folder/to/file/TEST_FILE.xlsx";
$writer = PhpOfficePhpSpreadsheetIOFactory::createWriter($spreadsheet, "Xlsx");
$writer->setPreCalculateFormulas(false);
$writer->save($destinationfile);

//SEND AN EMAIL TO ME: "FINISHED CRON"

I’m currently using DigitalOcean as my server with PHP Version 8.2.13 and the composer.json file says:

{
    "require": {
        "phpoffice/phpspreadsheet": "^1.29",
        "phpmailer/phpmailer": "^6.9.1"
    }
}