It is possible without duplicating the layer. You can do the following.
- On the layer you want to fill, select the area you want to fill. You can use the fuzzy select tool() for this.
- Create a new transparent layer and use the bucket fill tool() to fill the selected area by clicking within that area.
The result is a new layer with just the color of the shape and everything around isn't affected because of the transparency. In some situations you can also just select the background and invert the selection.
This workflow can then be applied to the question by doing a border selection(Select->Border) and filling the selection on a new transparent layer to create the image below.