Write file in background

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