Can one 40k army fight another of the same?
There is nothing in the rules to prevent two armies from the same codex from fighting one another.  I would just be sure that you can tell who each model belongs to; this is not too difficult once they are painted, but it could be easy to lose track of who is on which side if there are all just bare plastic.

With the current fluff, Necrons Overlords have their own Dynasties and it is easy to justify a power struggle between two of them.  Most other codexes can have fluff reasons to fight amongst themselves.