It is not unexpected that formaldehyde condensates with metformin, leading to a degradation product that is not a good NDMA precursor. As such formaldehyde could be a nitrosation prevention additive here, just like antioxidant use in other cases, (but due to its reactivity it might indeed not be the best fit). This means that the xx ppm nitrite you spiked led to lack of robustness without formaldehyde and that part of the NDMA might have been formed during the preparation. Overall the method doesn’t seem to be robust in xx ppm nitrite.
Mechanism of metformin formaldehyde scavenging:
https://doi.org/10.1002/tox.22982
Note that formaldehyde-catalysed nitrosation also has a higher pH optimum than classic nitrosation, so you have to be critical on your sample preparation when wanting to use this strategy:
Formaldehyde Catalysis of Nitrosamine Formation - New Scientific Knowledge & Development - Nitrosamines Exchange
It could also be that other ingredients in your product have a reactivity towards formaldehyde.
Note that in the the state-of-the-art there are different methods described for testing metformin preparations, also tackling robustness.
NDMA analytics in metformin products: Comparison of methods and pitfalls - ScienceDirect
(This is assuming NDMA can be formed from metformin itself, though in medicine detections a more prevalent root cause is dimethylamine contamination. In that case, metformin would still trap the possible catalyst formaldehyde possibly, rather than activating dimethylamine for formaldehyde-catalysed nitrosation if the pH allows it.)
Avoiding N-nitrosodimethylamine formation in metformin pharmaceuticals by limiting dimethylamine and nitrite - ScienceDirect