Add if loop to allow output file to be specified