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