in reply to how do I write directly to a file

You're printing to a file after you've closed it. Using -w in your script would have caught this problem.

Also, you need to check the return value from open like this:

open(COLORS, ">>colors.txt") || die "Can't open colors.txt: $!\n";

Replies are listed 'Best First'.