一緒 and 同じ: doing something together and having the same thing
Distinguish doing something together from having the same kind or content, including the form of 同じ before nouns.
Who acts together
友達と一緒に帰りました。 says that someone went home together with a friend. 一緒, read いっしょ, describes doing the action together, with と marking the companion.
この二つを一緒に運んでください。 asks someone to carry these two items together. It also applies to handling objects together, not only people sharing an activity.
The same kind or content
友達と同じ本を買いました。 says that someone bought the same book as a friend. This can mean the same title or kind, not necessarily a single copy purchased jointly.
同じ質問を二度しました。 says that someone asked the same question twice. Before this noun use 同じ質問, not 同じな質問.
Overlapping meanings and different actions
値段は一緒です。 can mean that the prices are the same. 一緒 also expresses sameness and is not limited to people doing something together.
同じ店で買いましたが、一緒には行きませんでした。 says that the people bought things at the same shop but did not go together. A shared location differs from accompanying one another.
Must someone who 友達と同じ本を買った have gone to the bookstore with the friend?
Show the answer and why
No. The books match, but the sentence does not specify a joint visit. Accompanying someone can be stated separately with 一緒に行く.

