Atmel ICE debugger causing incorrect execution! Never seen this before.

Hi,

In my efforts to interface with a quadrature encoder using SPI, I discovered:

If I use Atmel ICE debugger + Atmel Studio and program UNO using either ISP, debugWIRE, or avrDude, the execution is not as expected.

It however works correctly if I use Arduino IDE to upload the code.

Same exact code!

Have you folks seen this before? I discovered after I spent a week debugging the code and then decided to suspect the unthinkable... the debugger.