We all think that if we have an idea last thing at night that we'll remember it in the morning. Unfortunately that very rarely happens because our brains process lots of things whilst we sleep. If we write our ideas down before we go to sleep it gives our brains one less thing to worry about and helps us to sleep better. It also means that our brain can work on that idea whilst we're asleep so it'll be even better the next day.