in reply to split file at line number

If you are on *nix, you could just use the split command:
split -l 500 file.txt
This will dump out a lot of new files in your current directory (40 files to be exact: 20000/500).

If you want to use perl, you can make use of the special variable (INPUT_LINE_NUMBER): $.