The behavior from flatten() is not identical to the way Paint.NET flattens project files. This is especially the case when a translucent pixel is on the bottom layer. Despite blending mode being set to Normal, the color appears to shift when flattened.
This can be verified by printing the RGBA value at certain points in the image before and after the blending process and comparing them to Paint.NET flatten.