Add shutdown hook for saving history to history file