Lucius Malfoy is Dobby's master and Dobby worked in Malfoy Manor until Harry Potter freed him. Dobby knew about Tom Riddle's Diary and wanted to prevent Harry Potter from going to Hogwarts. But the unique nature of Elf magic prevented him from betraying his master.