He didn't need Dobby, but he wanted him, because he had love and ambition. Because, well, a young dark lord did need a loyal house-elf and he had the means to make Dobby one. So, Harry hugged the house-elf to him, encouraged him to obey and be loyal, wrapped the spell around them that bound him to Harry's will, that shifted his personality to match Harry's good choices.