branchmap: use a context manager when writing the branchmap
This is cleaner and safer. The previous code date from long before we had context manager available.
This is cleaner and safer. The previous code date from long before we had context manager available.