A lot of folks seem to have problems with that manufacturer's library. I have seen several implementations without the library as well.
I don't have one of those devices, so I can't really help you further, except to say that you did find a sketch that seemed to work, so I would recommend using that one as a basis for your implementaion.
As well, if you Google "HMC5883L library arduino" (but without the quotes), you will find many threads here and elsewhere. They would be worth reading.