Changed write function to receive write file options as a third param