The script buffer stores an ordered list of commands such as loading/discarding resources, drawing/overlaying pictures and adding views to the background (add.to.pic) which are later saved in a save game.
The AGI memory layout is very dependent on the order in which things are loaded, discarded, etc., so the script is necessary to ensure that this order is conserved. When a game is restored, the script is executed to ensure the interpreter's memory is in exactly the same state as it was when the game was saved. The script buffer is cleared when new.room is called.
For a more detailed description of AGI memory and the script buffer, see the Memory and Script article.