Changed it so that it writes the file instead of printing the table - not sure which one is actually wanted.