Changed how tempory filename is created and handled. Now follows example in mktemp documentation.