[bugfix] reflinks.py: If urlobj.write fails, the file will not be closed
[bugfix] reflinks.py: If urlobj.write fails, the file will not be closed

Bug: T276747
Change-Id: I0c7e71715b03dc9fb94ba31482f5d34fd0d17da2

wikimedia/pywikibot-core,wikimedia/pywikibot-core