This is a debug connected environment but the SWD pins are at PTC4 and PTA4 (I don't have a JTAG interface). I forgot to mention that I use S9KEAZN64 mcu. Peripherals connected to PTA2 are KB interrupt, UART0 and I2C0, but I am not using them. I'm only using UART1 if this means anything.
Below is a picture from the reference manual for PTA2 pin.

Update: Since that this issue is not caused by updating FTM_CnV register (it was just my luck that it pulled down the pin at the same time multiple times in a row).
I set a breakpoint at the beginning of the while loop and counted how many times it looped before pulling down the pin.
It was always the same number of times.
This problem is just weird and I would love some help on this.