Sofia Vergara and Joe Manganiello got a surprise house visit from a guy claiming to be a family friend -- except he was an uninvited stranger, so he got busted for trespassing ... law enforcement sources tell TMZ. Our sources say the man managed to…