Ah, I think I know what the problem is. In order to figure out what region you're playing in, LibRealmInfo needs to look at your character's GUID, which isn't available before the login process is finished. Try wrapping the code up like this:
Code:
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
-- all the other code here
end)
This will delay running the rest of the code until the login process is complete.
Re: The message spam, I forgot about that... the library is designed to be embedded in the addon using it, so if it's installed as a standalone addon, it assumes you're a developer and want debugging info. The simplest way to fix that is to move the LibRealmInfo.lua file from the LibRealmInfo folder into your addon's folder, then add a line reading "LibRealmInfo.lua" in your addon's TOC file, just before the line that names your addon's Lua file. Then you can delete the LibRealmInfo addon folder.