It's important to know your professor's expectations regarding working with other students. Most faculty think that study groups are a very good idea, but unless they give very specific instructions to the contrary, they expect all written work—homework, lab reports, computer programs, papers, take-home quizzes or tests—to be done individually. Students get into trouble on papers or take-home exams when they step over the line between talking about ideas and concepts with other students and discussing in too much detail the structure of the paper and the specific examples to use to support each idea. You can imagine that the papers of students who talk in that kind of detail will be unacceptably similar. Whether it's a homework worth 1% of your final grade or an exam worth 25%, you need to understand your professor's guidelines and abide by them. If you have any doubt at all about the amount of collaboration your professor considers legal, it's your responsibility to ask for clarification.
There is an excellent discussion of this issue on the UC-Davis web site: " Unauthorized Collaboration: What Students Need To Know"