Your for loop copies the file you cat'ed output of 'file', defines the variable file by greping file (which you already cat'ed), and then copy file (which you cat'ed) as many times as entries are found in file (which you cat'ed) to test, overwrite 'test' as many times as entries were found.
Then you execute 3 files..
1) the file you cat'ed
2) and /tmp/[unix)$(date +y)log
for ENTRY in $(cat /some/file)
do
workfile=$(grep -i key $ENTRY)
cp ${workfile} test.$ENTRY
done
Assuming /some/file holds a list of diffrent files....
Now it sets the variable workfile to the content of the result of grep'ing key out of $ENTRY, and then copies the $workfile to the current path test.$ENTRY, where $ENTRY is the filename (if the (some/file contains other filenames/paths) of the file you grep'ed ALL lines containing the word 'key' in it.
At least it doesnt overwrite the file 'test' a dozen times anymore...
Can you elaborate a bit more of what you'd like to achieve?
For example with the logfiles and by the call of the 'file'?
EDIT:
Been late, of course, if test is a directory, all files are copied there.