Fixed write generated class to file method + testing.