add function to save trajectories to files