Which language you'd like to use? When a line end is a separator, it's not that hard. Pseudocode below
Code:
char c;
int count=0;
int max=50;
while(file_not_empty(file)){
c=getchar(file);
if(c=='\n'){
count++;
if(count==max){
close_file(outfile);
/* open new one or exit */
} else{
write_line_ending_html_code(outfile);
}
} else writetofile(outfile,c);
}