Currently, there is no way of retrieving historical anonymous code block executions. If you close the IDE, then you lose what you have in the anonymous block, but if you are working with the Developer Console in the browser, and log out of your current session, you still have the last executed code when you log back in.