Write file in background

Write wasn't execute in the background which may cause latency when writing big files. Fixed here.