Hi phew,
In your first example, I think this is just a sloppy mistake being made in casual language. You're right: "I just happened to look out the window" would be grammatically correct.
In the second example, you're right that "happen to" couldn't be replaced by "by chance", it's closer to: "Actually, I think you do a lot of things right."
It's difficult to say for sure without knowing the context, but there could be an implication that A is lucky B thinks that. In which case, B might be using "happen to" to convey the subtext: "Actually, as chance would have it/as crazy as it may seem, I think you do a lot of things right..." Can you see how that might be implied?