Extracted print_file method