Modified RetrieveSensorData to write into a file