This was supposed to solve the timer stopping sometimes when the application was in the background. It was actually stopping because of battery optimizations.
It is writing the exported sets.csv correctly, however afterwards the device has no access to any files on it's system anymore.