repoman: fix random package.use.stable.* failure

It failed to work randomly, since setcpv did not always use the correct
value for the effective ACCEPT_KEYWORDS of the current profile.
refactor contents file writing to its own function

This CL refactors out the functionality of writing a contents dicionary
to file. That functionality is required by a change in the chromeos
chromite repository.

BUG=chromium:229234
TEST=None

Change-Id: I851724408b1d10827eee2ea8d67bdca9ad90c455