although enough answers have already been stated, and since this question does completely sound like a homework assignment, I will try to top them all: does that "bed file" come from a previous gene annotation process which is printing a comma character at the end of each gene so, oh my, you need to remove the last gene's comma character?
my first choice for removing last comma characters would be Sukhdeep's sed -i 's/,$//' file.bed
, but if the situation is the one I've just described in the previous paragraph then I would better suggest you to correct your previous script, as it's not a good idea to leave imperfections inside a script and try to correct them afterwards, specially if you're learning to code.
and as a final top guess... would that annotation script be written in perl, where the gene information is being printed in a similar manner to
foreach $gene (@genes) { print "$gene," }
? if so, you may correct your problem by using the join function like
print join ",", @genes
the output of your annotation script won't have that comma at the end of each line.