Did you enable XIRQ? (X-interrupt mask bit in CPU status register). Also is XIRQ vector set up properly?
It's not clear, did you set up your Port Pin direction before AC failure, and Pin gets tristate on AC failure? Or maybe your XIRQ ISR is supposed to set up pin direction and then toggle the pin?
In your XIRQ routine, do you write your NV stuff and exit, or do you write and start looping forever in XIRQ ISR? If you exit, then CPU will reenter ISR and process will continue until reset or until XIRQ is high again. Data could get corrupted if reset happens in the middle of write.