Write output in csv format by removing extra brackets