I think the issue is that once you create a new Layer, the original layerCollection object becomes invalid, it doesn’t auto-update.
so the myLayers = app.project.activeItem.selectedLayers; etc…
needs to be re-evaluated every time the button is clicked, not just at the initialising of the window.
Edit: Since you’re working from selectedLayers, (not app.project.activeItem.layers, which is what I was thinking of), this will be especially true. The selectedLayers isn’t up to date anymore