Use File.createTempFile() instead of custom function