Added file write function.