You have to wait until the queue is processed before removing the file.
Without knowing the implementation details of the queue it is hard to answer your question, but if your queue is processed before the script ends, you can use register_shutdown_function http://www.php.net/manual/en/function.register-shutdown-function.php to run a cleanup function that removes the file
register_shutdown_function(function() use (filename){
if (file_exists($filename)) {
unlink($filename);
}
})