Flip function randomly flips camera view

We run a camera that receives instructions through an i2c interface when the camera view needs flipping.
Our technician has told us that he inspected the i2c and it wasn’t receiving an instruction to flip at the time. A brief run down of the use case is this:
i2c receives code for flip, updates a text file with the mode of the camera. the file will either have the text “standard” or “flip”. When the camera runs if the file reads flip it runs the flip function otherwise it does nothing.
This is the code pertaining to flip:

if code is flip:            
write_to_camera_orientation('flip')
if code is standard:
write_to_camera_orientation('standard')

            gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
            gray_three = cv2.merge([gray,gray,gray])
            with open('flip') as f:
                read_data = f.read().rstrip('\n')
            if read_data == 'flip':
                gray_three = cv2.flip(gray_three, -1)

My inspection at this stage is the case of the statement to load from file can only be shown to read a “flip” value or “standard” and if the standard is received then it won’t do anything. so i’m guessing the error is with the flip function itself.