It seems this should work for you:
total_line=$(wc -l /home/myfile |cut -d " " -f1) #get line count
insert_point=$(($total_line-2)) #get insert point
sed "$insert_point a insert_text" /home/myfile #insert using append command (a)to sed.
Notice double quotes for variables, (").
Replace "insert_text" with what you want including $variables
You could paste the following in to the above code to confirm you have set the variables correctly.
echo total_line= $total_line
echo insert_point=$ insert_point
When it all looks right you need to write the file.
So use one of the following:
#writes /home/my_new_file and preserves /home/myfile
sed "$insert_point a insert_text" /home/myfile > /home/my_new_file
or use the -i option
edit files in place (makes backup if extension supplied)
#overwrites /home/myfile!! be careful!!
sed -i.bak "$insert_point a insert_text" /home/myfile