It's a bad idea to parse the output of
ls. The primary job of
ls is to list the attributes of files (size, date, etc.). The shell itself is perfectly capable of listing the contents of a directory, with wildcards.
It's quite simple to run
md5sum on all the files in the current directory and put the output in a file: redirect its output to the desired output file.
md5sum * >/tmp/md5sums.txt
If you want the output to be sorted by file name, pipe the output of
md5sum * | sort -k 2 >/tmp/md5sums.txt
Note that numeric sorting (
-n) will only give useful results if the file names are purely numeric. If all you need is for the output to be deterministic, how you sort doesn't matter.