A new image defaults to a layer named Background.
Create a new layer, it is called Layer 2.
Create a new layer, it is called Layer 3.
Delete Layer 2 leaving Background and Layer 3
Create a new layer, it is called Layer 3.
We now have Background, Layer 3, and Layer 3.
It would appear that the new layer creation code is counting the layers and labeling the new one accordingly, which does not take into account layer names.