I use this to duplicate an element. (Element#1 to element#2)
After duplicating, how can I delete element#1?
Not sure your script is doing what you think - getting the bounding box of an element and finding the centroid of the bounding box it contains doesn’t duplicate an element, but this could be used as the start of a new graph to place a new instance at the centroid.
In any case I prefer the Tool.Eraser node from the Steam Nodes package but both should work for you.