Dobby was eager to help, and he knew the rules. It wasn't the first time that little elf helped him warn Potter. Three and half years ago, Draco sent Dobby to warn him of the things that were happening at Hogwarts in their second year. Not that it helped much. Hermione still ended up in the hospital wing.