output_name in main was set to argv[2] but then argv[2] rather than output_name was used later in the function.