The reason for the time train at the end of BTTF3 is because the writers had basically written themselves into a corner. Marty helps save Doc from Buford Tannen, but Doc is still in the past(possibly in jail for stealing the train) and will still die in the past. If they didn't have Doc return, people would walk out of the theater angry because they just saw a pointless, depressing movie. This being a comedy, you want to end on a happy note. Now, the audience gets a resolution to the story and the friendship. Doc is still alive and involved in other adventures. People leave the theater with a warm feeling on a high note.