Dobby's motivation in Harry Potter and the Chamber of Secrets seems to be to protect Harry at all costs from the opening of the Chamber.
"No, no, no," squeaked Dobby, shaking his head so hard his ears flapped. "Harry Potter must stay where he is safe. He is too great, too good, to lose. If Harry Potter goes back to Hogwarts, he will be in mortal danger."
"Why?" said Harry in surprise.
"There is a plot, Harry Potter. A plot to make most terrible things happen at Hogwarts School of Witchcraft and Wizardry this year," whispered Dobby, suddenly trembling all over. "Dobby has known it for months, sir. Harry Potter must not put himself in peril. He is too important, sir!"
(Chamber of Secrets, Chapter 2, Dobby's Warning).
Dobby doesn't seem to have noticed that, as a half-blood, Harry wouldn't have been a prime target for the Monster of Slytherin, but maybe he didn't overhear the Malfoys going into details on that part of the plot.
Anyway, Dobby's plan for protecting Harry seems to be roughly as follows:
- Warn Harry not to go back to Hogwarts.
- Steal Harry's mail so that he thinks his friends don't want him to go back to Hogwarts.
- Try to get Harry expelled from Hogwarts by performing magic in his house.
- When Harry ignores his warning, block the entrance to Platform Nine and Three Quarters.
- When Harry gets to Hogwarts by another method, bewitch a Bludger to attack Harry so that he is sent home, "grieviously injured".
- Warn Harry again.
There are so many things which can and do go wrong with this plan, but the thing that all Dobby's schemes have in common is that they allow Lucius Malfoy to reopen the Chamber of Secrets.
Wouldn't a much simpler, less troublesome and more effective plan have gone something like this?
- Steal the Riddle diary and hide it somewhere.
- Prevent the reopening of the Chamber of Secrets.
This would be an iron-clad method of safeguarding Harry from the Malfoy plot, and would have the added benefit of also protecting the hundreds of other students and staff at Hogwarts (who Dobby doesn't seem to give a second thought for).
Of course, this would mean that Dobby would have to betray his masters - but then again he was already doing that by warning Harry. His actions throughout the book are one big continuous act of disobedience.
The key to this one is probably whether Dobby knew about the specific involvement of the diary in the Malfoy plot. If he didn't then he wouldn't know to steal it. However, Dobby certainly knew about the diary at the end of the year.
The elf was doing something very odd. His great eyes fixed meaningfully on Harry, he kept pointing at the diary, then at Mr Malfoy, and then hitting himself hard on the head with his fist.
(Chamber of Secrets, Chapter 18, Dobby's Reward).
If he knew about the diary, why didn't he just steal it?