just realised I missed something, needed to add the write file to the second cut if statement