cardiff: Adding generic function to write gnuplot output file

This function makes some duplicated code generic and is a starting point
for multiple plotting.