Added write to csv for plotting data.