added write file with chunks