reading database writing into txt file