add function save_data

add function to save data into text file