bibtools/bibcore.py: fix tricky bug related to output encoding

See the comment in the commit.