%%capture cap captures different outputs of the current cell (depending on --no-stderr, --no-stdout, or --no-display options) and stores them in cap.
The capture object cap is only created/updated at the end of the cell execution. To display its content, using cap() (same as cap.show()), or save it to a file, you have to do it in another cell.
In a first cell, cap is filled with output contents, and in a second cell cap content is saved and displayed:
%%capture cap
del cap # delete previously existing cap variable 
print("capture me if you can!")
with open('output.txt', 'w') as f:
    f.write(cap.stdout)
cap()
capture me if you can!
When %%capture cap, cap.stdout, and cap.show() are all in the same cell:
%%capture cap
del cap # delete previously existing cap variable
print("capture me if you can!")
with open('output.txt', 'w') as f:
    f.write(cap.stdout)
cap()
it raises a NameError: name 'cap' is not defined error.
If it does not raise an error, that means that you had already initialized cap with some data (maybe running the very same cell but without the cap.output and cap.show()). 
In that case, that means that by adding cap.show() at the end of your cell, you add the content of cap to the outputs of this cell, so, you override cap content with "the new output of the cell + the previous content of cap".
As a result, the next time you will run the cell it will write in your file the previous "new output of the cell + previous content of cap".
Note that, in the examples above, the del cap is just here to raise errors when cap is called in the %%capture cap cell. This del cap is not necessary for normal use: cap's content is fully replaced when %%capture cap is called.