I can see no reason for outputting intermediate files with this script. Code should be refactored into outputting straight to out.pdf.