Fixed a bug regarding the automatic recording option

a strange write to file bug appeard due to a wrong default mode in the
while loop for the state machine