Move CSV generation to dedicated file

To use a better implementation of CSV generation, it is better to keep
the generation algorithm in dedicated file.