Speeding up the writting of temp files

Iterating manually is bad