This can be fixed by saving the live script just before exporting the file.
% Name of output file
outputFile=strcat(filebase,timestr,'_OUTPUT.pdf');
% Export the PDF file to subfolder of current run
pdfPath = strcat(newdir,'/',outputFile)
% Save the live script
save(strcat(simfile,".mlx"));
% Export the PDF file
pdfFile = export(strcat(simfile,".mlx"), pdfPath, OpenExportedFile=false, HideCode=true);