added writetree through temp file