write to file
Stage 4 write to file