Occasionally, just writing without a plan is a worthwhile exercise, especially early in the conception so you can hear the voices of your characters. But I’d leave writing any actual script of an episode until you know how it ends. You’ll think of a better ending as you write the script. But if you don’t have any ending when you start writing, you almost certainly won’t think of one.