Added save_trajectory helper function.