Fixed writing to files

tmpPath variable was being destroyed, causing pointers to point to no
longer valid memory