Flam is a tiny village at the end of a fjord. A beautiful place, but tiny. That means the accommodation market is tight.
And there are a lot of comments on here about the effects of the cruise industry there.
If you stay overnight you are then on that ferry next day, or on the train back up to Myrdal for Bergen next day, or on the Norway in a Nutshell. Some people think that the NiN and the Coastal Voyage provides duplication of great scenery.
The elements of NiN onward from Flam can be booked independently but it doesn't work out a great deal cheaper. You could get off overnight at one of the other ports en route to Bergen- as some also have a morning boat to Bergen. I know someone (from the US) who did that last year, at a really well priced hostel in a lovely untouristed tiny port-then got the next morning's ferry to do a request stop for her.
But I can't remember what that port was called, and can't find her Travel Agent's itinerary from last year- it's buried too far back in my e-mails.