in reply to Directory Stuff

But, If i use a path to the directory it does not work.

You might have been able to figure this out for yourself if your script didn't ignore useful clues. If a library routine returns an error by setting $!, check it! That means writing

opendir(DIR, 'c:/perl/test') or die "c:/perl/test: $!"; ... open(MYFILE, ">myfile.txt") or die "myfile.txt: $!"; open(THEFILE, "<$file") or die "$file: $!"; ...
Purists will tell you to also do
close(MYFILE) or die "c:/perl/test: $!";
in case the disk fills up and the script is unable to cleanly close the file.

That said, understanding that readdir() returns names, not paths, is key to understanding the problem. Here, consulting the perl documentation help. The blurb on readdir() in perlfunc spells it right out:

If you're planning to filetest the return values out of a readdir, you'd better prepend the directory in question. Otherwise, because we didn't chdir there, it would have been testing the wrong file.