Start in the same state after turning the power off and on

This may be nothing to do with your issues, but you are writing to the same memory location every time around your loop which could be 1000's of times a second. With a real EEPROM device, that would wear out that memory address in a couple of minutes or so.

I've not used a DUE but you are using FLASH memory for your storage. Does your library take care of erasing the memory (location/page/sector) before writing the new value. FLASH needs to be erased (back to 0xFF I think) if you want to write a new value.