Multithread the file writing