My guess is that your "debug printing" is causing something to be evaluated when it otherwise wouldn't be, causing a transaction to begin within a transaction.
My guess is something is being lazily evaluated as usual, but if that is forced within a transaction, well, last I checked the GHC I/O system used STM internally so unsafePerformIO debug prints could well cause nested transactions.