Fixed csv formatting bugs: utf-8 encoding exception and newline characters are now escaped