REF: Added grid in graphs and generating the output file with same extension as the input