Added savetofile
added test for savetofile