added printwriter class to write to file instead of stdout