diff reports two files differ, although they are the same!

Odd .. can you try cmp? You may want to use the '-b' option too.

cmp man page - Compare two files byte by byte.

This is one of the nice things about Unix/Linux .. so many tools :)


diff file1 file2 | cat -t

The -t option will cause cat to show any special characters clearly - eg. ^M for CR, ^I for tab.

From the man page (OS X):

 -t      Display non-printing characters (see the -v option), and display tab characters as `^I'.

 -v      Display non-printing characters so they are visible.
         Control characters print as `^X' for control-X; the delete character
         (octal 0177) prints as `^?'.  Non-ASCII characters
         (with the high bit set) are printed as `M-' (for meta) followed by the
         character for the low 7 bits.

Might the differences be caused by DOS vs. UNIX line endings, or something similar?

What if you hexdump them? This might show differences more obviously, eg:

hexdump -C file1 > file1.hex
hexdump -C file2 > file2.hex
diff file1.hex file2.hex