I’ve known quite a few kids who spoke one language at home, and another at school or in public. None of them ever confused the languages, as far as I could see. Even as toddlers, the ones who spoke Spanish at home, for example, never tried to speak Spanish to me.
It helps if you or someone close to the child are fluent in the second language. A child who “learns” Spanish from Dora or Diego won’t become fluent.
I even knew a little boy who learned Swedish from his father, Korean from his mother, and English at daycare. Like others have said, a child’s brain is programmed to learn to speak and they will quickly and easily absorb more than one language. Think of immigrants who struggle to learn the language and always speak with an accent or with some errors or grammar. Their children will easily learn both the parents’ language and the local language without any accent or errors. Even children who are deaf and learn sign from their hearing parents, will naturally develop a more fluent and grammatically correct form of sign.
There’s a very interesting book about language development called “The Language Instinct.” I read it in college, and the first half of the book gives many examples of how children learn to speak and what happens when they don’t learn a language or are deaf. The second half of the book gets into a detailed study of syntax, which is like reading a foreign language and not nearly as fascinating to the average reader as the first half of the book.