Print functions take output file parameter

Functions print_dict and print_list take outfile parameter (file where
to print output). This indirection allows for testing without patching
sys.stdout (patching stdout can break debugging tools).

Change-Id: Id4b76c5b7d9a8509eb0c662b498855cf9b261a82