Are you writing your own shell?

If "ls > file.txt" is giving you that error from a regular shell, then something is wrong with the shell.