PHP can't unlink file after fclose
I've run into this issue before and been able to remedy by forcing garbage collection after closing the file and before unlinking it:
gc_collect_cycles();
By far not the best solution, but it did resolve an issue I had deleting files that had been previously opened and closed lines before.